//
//  MainVC_Work.m
//  liBaQiang
//
//  Created by 奇林刘 on 2018/10/9.
//  Copyright © 2018年 liu. All rights reserved.
//

#import "MainVC_Work.h"
#import "MainVC_Work_ButtonsCard.h"

@interface MainVC_Work ()

@property (nonatomic, strong) BaseButton *BannerButton;
@property (nonatomic, strong) BaseButton *searchButton;
@property (nonatomic, strong) NSMutableArray<MainVC_Work_ButtonsCard *> *buttonsCardsArray;

@end

@implementation MainVC_Work

#pragma mark - lifeCycle
- (void)configSelf {
    self.scrollContentView.fp_backgroundColor(HexadecimalColor(@"#F5F6F8"));
    [self changeScrollMode:ScrollModePortrait];
}

- (void)allocateComponents {
    [self allocateBannerButton];
    [self allocateSearchButton];
    [self allocateButtonsCardsArray];
    
    [self countDownDawn];
}

- (void)configComponents {
    [self configBannerButton];
    [self configSearchButton];
}

#pragma mark - usedMethods
- (void)countDownDawn {
    Liu70CountDownLabel *countDown = (Liu70CountDownLabel *)[[Liu70CountDownLabel alloc] init].fp_font(BoldRPXFont(20)).fp_textColor([UIColor blackColor]).fp_backgroundColor([UIColor whiteColor]);
    
    [self.scrollContentView addSubview:countDown];
    [countDown mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.BannerButton);
    }];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *timeString = @"2019-02-05 00:00:00";
    [countDown startCountDownToEndDate:[formatter dateFromString:timeString] finish:^{
        [SVProgressHUD showInfoWithStatus:@"黎明计划升空！"];
    }];
}

//allocate
- (void)allocateBannerButton {
    self.BannerButton = [[BaseButton alloc] init];
    [self.scrollContentView addSubview:self.BannerButton];
    [self.BannerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.scrollContentView);
        make.height.equalTo(@(RPX(180)));
    }];
}

- (void)allocateSearchButton {
    self.searchButton = [[BaseButton alloc] init];
    [self.scrollContentView addSubview:self.searchButton];
    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.BannerButton);
        make.top.equalTo(self.BannerButton.mas_bottom).offset(-RPX(20));
        make.width.equalTo(@(RPX(355)));
        make.height.equalTo(@(RPX(44)));
    }];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
    [self.searchButton addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchButton).offset(RPX(15));
        make.left.equalTo(self.searchButton).offset(RPX(152));
        make.width.height.equalTo(@(RPX(14)));
    }];
    
    UILabel *label = [[UILabel alloc] init]
        .fp_text(@"搜索")
        .fp_font(RPXFont(14))
        .fp_textColor(HexadecimalColor(@"#B3B3B3"));
    [self.searchButton addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView.mas_right).offset(RPX(10));
        make.centerY.equalTo(imageView);
    }];
}

- (void)allocateButtonsCardsArray{
    self.buttonsCardsArray = [NSMutableArray array];
    NSDictionary *plist = [HandyMethods getPlistDicByName:@"MainVC_Work_Property"];
    NSArray *cards = plist[@"buttonCards"];
    
    for (int i=0; i<cards.count; i++) {
        NSDictionary *card = cards[i];
        NSString *title = card[@"title"];
        NSArray *descriptions = card[@"descriptions"];
        MainVC_Work_ButtonsCard *previousCard = (i==0) ? nil : self.buttonsCardsArray[i-1];
        MainVC_Work_ButtonsCard *currentCard = [[MainVC_Work_ButtonsCard alloc] initWithButtonDescriptions:descriptions title:title];
        [self.buttonsCardsArray addObject:currentCard];
        [self.scrollContentView addSubview:currentCard];
        
        [currentCard mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.scrollContentView);
            if (i == 0) {
                make.top.equalTo(self.searchButton.mas_bottom).offset(RPX(10));
            } else if (i == cards.count - 1) {
                make.top.equalTo(previousCard.mas_bottom).offset(RPX(10));
                make.bottom.equalTo(self.scrollContentView).offset(RPX(-10));
            } else {
                make.top.equalTo(previousCard.mas_bottom).offset(RPX(10));
            }
        }];
    }
}

//config
- (void)configBannerButton {
    [self.BannerButton setBackgroundImageWithImageName:@"index_banner"];
}

- (void)configSearchButton {
    self.searchButton
        .fp_addTargetActionForControlEvents(self, NSSelectorFromString(@"searchTap"), UIControlEventTouchUpInside)
        .fp_backgroundColor([UIColor whiteColor])
        .fp_cornerRadius(RPX(4))
        .fp_shadowColor(HexadecimalColor(@"#0084FF"))
        .fp_shadowOffset(CGSizeMake(0,RPX(3)))
        .fp_shadowOpacity(0.08)
        .fp_shadowRadius(RPX(4));
}



@end
